package com.bsh.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bsh.repository.DaoCloudReferrals;
import com.bsh.service.CloudService;
import com.bsh.utils.Pager;
import com.mysql.jdbc.StringUtils;

/**
 * 商币
 * @author gsh
 *
 */
@Service
@Transactional
public class CloudServiceImpl implements CloudService {
	@Autowired
	private DaoCloudReferrals refDao;
	//@Autowired 
	//private DaoCloudMoneyLog logDao;
	

	/* (non-Javadoc)
	 * @see com.bsh.serviceImpl.CloudService#getReferralsPage(com.bsh.utils.Pager, java.lang.String, java.lang.String)
	 */
	@Override
	public List<Map<String, Object>> getReferralsPage(Pager pager,String userName,String relUserName) {
		StringBuilder sb =new StringBuilder();
		if(!StringUtils.isNullOrEmpty(userName))
			sb.append(String.format(" and user_name like '%%%s%%' ",userName.trim()));
		if(!StringUtils.isNullOrEmpty(relUserName))
			sb.append(String.format(" and rel_user_name like '%%%s%%' ",relUserName.trim()));		
		List<Map<String, Object>> list = refDao.getReferralsPage(pager,sb.toString());
		return list;
	}
	
	/* (non-Javadoc)
	 * @see com.bsh.serviceImpl.CloudService#getReferralCountPage(com.bsh.utils.Pager, java.lang.String, java.lang.String)
	 */
	@Override
	public List<Map<String, Object>> getReferralCountPage(Pager pager,String userName,String count) {
		StringBuilder sb =new StringBuilder();		
		if(!StringUtils.isNullOrEmpty(userName))
			sb.append(String.format(" and u.name = '%s'",userName.trim()));
		if(!StringUtils.isNullOrEmpty(count))
			sb.append(String.format(" and t.c = %s",count.trim()));		
		List<Map<String, Object>> list = refDao.getReferralsCountPage(pager,sb.toString());
		return list;
	}	
	
}
